﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WarriorRush.UserInterface;
using WarriorRush.GameDynamics.Utilities;

namespace WarriorRush.GameDynamics.SpecialAbilities
{
    
        public class Evade : SpecialAbility
        {

            public Evade()
                : base()
            {
                ReplacesAttack = false;
                RequiresAddtionalTarget = true;
                AbilityType = AbilityTypes.Evasion;
            }


            public override bool Execute(CharacterClass abilityTarget, Arena arena, List<CharacterClass> additonalTargets)
            {
                var swapTarget = additonalTargets.FirstOrDefault();
                var currentSquare = AbilityOwner.Square;
                AbilityOwner.Square = swapTarget.Square;
                swapTarget.Square = currentSquare;

                return base.Execute(abilityTarget, arena, additonalTargets);
            }
            public override void CalculateTargets()
            {
                Targets = new List<SimplePoint> { new SimplePoint(0, 0) };
                for (var n = 1; n <= Power; n++)
                {
                    Targets.Add(new SimplePoint(0, n));
                    Targets.Add(new SimplePoint(0, -n));
                }
               
            }

            public override SelectionHandler GetAllTargets(Arena arena, ArenaSquare target)
            {

                return new SelectionHandler()
                {
                    Squares =
                       arena.GetTargetedSpaces(AbilityOwner.Square, Targets, true)
                           .Select(f => new Selectable() { Square = f }).ToList(),
                    SelectType = HighlightType.Targetable,
                    IsReplacedSelection = true,
                    MaxSelections = 1

                };
            }

            public override SpecialAbility GetInstance(int power)
            {
                var newInstance = new Evade();
                newInstance.Power = power;
                newInstance.CalculateTargets();
                return newInstance;
            }


        }

    
}
